import React from 'react';
import {Router, Route, Switch} from 'dva/router';
import {LocaleProvider} from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import {getUserLayout, getMainLayout, getUserNavList, getMainNavList} from './config/nav';

export default function RouterConfig({history, app}) {
  const UserLayout = getUserLayout(app);
  const MainLayout = getMainLayout(app);
  const userNavList = getUserNavList(app);
  const mainNavList = getMainNavList(app);

  // TODO 登录和权限控制考虑使用高阶组件
  return (
    <LocaleProvider locale={zhCN}>
      <Router history={history}>
        <Switch>
          <Route path="/users_login" render={props => <UserLayout {...props} userNavList={userNavList}/>}/>
          <Route path="/" render={props => <MainLayout {...props} mainNavList={mainNavList}/>}/>
        </Switch>
      </Router>
    </LocaleProvider>
  );
}
